<?php

namespace app\admin\controller;

use think\Db;
use think\Request;

class User extends Base
{
    public function getlist(){
        $params = $this->request->param();
        $where = [];
        if(isset($params['begin_time']) && $params['begin_time']){
            $where['createDate'] = ['egt', $params['begin_time']];
        }
        if(isset($params['end_time']) && $params['end_time']){

            $where['createDate'] = ['lt', $params['end_time'] . ' 23:59:59'];
        }
        if(isset($params['begin_time']) && $params['begin_time'] && isset($params['end_time']) && $params['end_time']){
            $where['createDate'] = [['egt', $params['begin_time']], ['lt', $params['end_time'] . ' 23:59:59'], 'and'];
        }
        if(isset($params['userName']) && $params['userName']){
            $where['userName'] = ['like', "%{$params['userName']}%"];
        }
        $model = model('User');
        $list = $model->where($where)->order('createDate desc')->paginate(10);
        $total = $model->where($where)->count();

        return $this->fetch('',[
            'datas' => $list,
            'total' => $total,
            'formget' => $_GET
        ]);
    }

    public function edit(Request $request){
        $param = $request->param();
        if(empty($param['id'])){
            return show(config('status.error_code'),'缺少参数','缺少参数');
        }
        $model = model('User');
        $info = $model->get($param['id']);

        return $this->fetch('',[
            'info' => $info
        ]);
    }

}